#!/bin/bash
#================================================================
#   Copyright (C) 2021 Sangfor Ltd. All rights reserved.
#
#  filename：config.sh
#  creator ：Zhongqianyan
#  data    ：2021年08月06日
#  descript：
#
#================================================================
# 1. install
function powerline_install() {
    if [[ ! -d "powerline" ]]; then
        git clone https://gitee.com/yanzhongqian/powerline.git
        sudo cp ./powerline/font/PowerlineSymbols.otf /usr/share/fonts/
        fc-cache -vf /usr/share/fonts/
        sudo cp ./powerline/font/10-powerline-symbols.conf /etc/fonts/conf.d/
cat>>~/.bashrc<<EOF
# powerline
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
EOF

        echo ". `pwd`/powerline/powerline/bindings/bash/powerline.sh">>~/.bashrc
fi
}

function yan_install()
{
    # delete
    read -p "delete firfox and son on, enter yes or no : " defaultapp
    if [[ $defaultapp = "y" ]] || [[ $defaultapp = "yes" ]]; then
        sudo apt-get --purge remove firefox thunderbird totem rhythmbox empathy brasero simple-scan gnome-mahjongg \
                                aisleriot gnome-mines cheese transmission-common gnome-orca gnome-sudoku remmina libreoffice-common
    fi


    # update sourcelist
    read -p "update sourcelist enter yes or no : " sourcelist
    if [[ $sourcelist = "y" ]] || [[ $sourcelist = "yes" ]]; then
        sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
        sudo rm -f /etc/apt/sources.list
        sudo cp -f sources.list /etc/apt/
    fi

    sudo apt-get update && sudo apt-get upgrade

    # install development environment
    read -p "do you want to install multi libs, enter yes or no : " multilibs
    if [[ $multilibs = "y" ]] || [[ $multilibs = "yes" ]]; then
        sudo apt-get install build-essential manpages-dev kernel-package \
             fakeroot libncurses5-dev libssl-dev flex bison libelf-dev net-tools \
             openssh-server autoconf automake libtool git fontconfig \
             libfile-next-perl ack-grep tree vpnc
    fi


    # vim
    read -p "install vim8.2 enter yes or no : " vim_install
    if [[ $vim_install = "y" ]] || [[ $vim_install = "yes" ]]; then
        sudo add-apt-repository ppa:jonathonf/vim && sudo apt-get update && sudo apt install vim
    fi
    sudo apt-get install ctags cscope
    sudo apt-get install vim-scripts vim-gtk
    sudo apt-get install ripgrep
    sudo apt-get install powerline
    sudo apt-get install python python3 python-dev python3-dev python-pip python3-pip

    # google Chrome
    sudo apt-get install wget
    wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    wget https://wdl1.cache.wps.cn/wps/download/ep/Linux2019/10702/wps-office_11.1.0.10702_amd64.deb
    sudo apt-get install libappindicator1 libindicator7
    sudo dpkg -i *.deb
    sudo apt-get -f install
    # Chinese input
    # 接着在应用程序中找到「Language Support」(语言支持)，
    # 更改「Keyboard input method system」(键盘输入法系统)为「IBUS」。
    # 重启系统，然后在Settings>Region & Language>Input Sources（设置>区域与语言>输入源
    # 中新增「Chinese(Intelligent Pinyin)」(中文(智能拼音))就可以使用中文输入法了。
    sudo apt install ibus-libpinyin
    sudo apt install ibus-clutter
    # powerline config
    powerline_install
    # autoremove
    sudo apt-get autoremove
}
yan_install
